package contest1609;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class H {
    static Scanner cin = new Scanner(new BufferedInputStream(System.in));//大量输入优化版本
    static PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));//大量输出优化版本
    static PrintWriter cerr = new PrintWriter(System.err, true);//开启调试模式,一般输出量不大，不需要buffered

    public static void main(String[] args) {
        //TODO AOJ开启你的ACM传奇人生
        cerr.println("----Start your ACM legendary life with AOJ(www.webturing.com)----");
        int n = cin.nextInt();
        ArrayList<ArrayList<Integer>> v = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i <= n; i++) {
            ArrayList<Integer> v1 = new ArrayList<>();
            v.add(v1);
        }
        int m = cin.nextInt();
        while (m-- > 0) {
            int num = cin.nextInt();
            if (num == 0) {
                int p = cin.nextInt(), q = cin.nextInt();
                v.get(p).add(q);
            } else if (num == 1) {
                int p = cin.nextInt();
                ArrayList<Integer> curV = v.get(p);
                if (curV.isEmpty()) {
                    cout.println();
                } else {
                    for (int i = 0; i < curV.size() - 1; i++) {
                        cout.print(curV.get(i) + " ");
                    }
                    cout.println(curV.get(curV.size() - 1));
                }

            } else if (num == 2) {
                int p = cin.nextInt();
                ArrayList<Integer> curV = v.get(p);
                if (curV.isEmpty()) {
                } else {
                    v.get(p).clear();
                }
            }


        }
        cin.close();//关闭输入流
        cout.close();//关闭输出流，这是必须的，否则一般不会自动刷新缓冲区
    }
}